package com.bjsxt.service.impl;

import com.bjsxt.service.feign.StorageServiceFeign;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class StorageServiceApi {

    private static Logger logger = LoggerFactory.getLogger(StorageServiceApi.class) ;

//    @Autowired
//    private RestTemplate restTemplate ; //ribbon

    @Autowired
    private StorageServiceFeign storageServiceFeign ;

    public void deduct(String productNo ,int count){
//        ResponseEntity<Void> responseEntity = restTemplate.getForEntity(
//                "http://storage-service/deduct/{productNo}/{count}",
//                Void.class,
//                productNo,
//                count
//        );
        ResponseEntity<Void> responseEntity = storageServiceFeign.deduct(productNo, count);
        if(responseEntity.getStatusCode()== HttpStatus.OK){
            logger.info("远程调用库存服务成功");
            return;
        }
        throw new RuntimeException("远程调用库存服务失败") ;
    }
}
